import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int f1 = 0;
        int f2 = 1;
        int f3 = 0;
        //创造斐波那契数
        while (n>f3){
            f3 = f1 + f2;
            //把n控制在f2与f3之间
            if(n<=f3){
                break;
            }
            f1 = f2;
            f2 = f3;
        }
        if(Math.abs(f3-n)<Math.abs(n-f2)){
            System.out.println(Math.abs(f3-n));
        }else{
            System.out.println(Math.abs(n-f2));
        }
    }

}
